home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
prodpack.zip
/
DB4PPSRC.EXE
/
_WHATPAR.PRG
< prev
next >
Wrap
Text File
|
1993-05-04
|
3KB
|
115 lines
FUNCTION _WhatPara && Comma Delimited String to Array
PARAMETER pa_array, pc_string, pc_delim
*--------------------------------------------------------------------
* NAME
* _WhatPara - copy data into array from comma
* delimited string.
*
* SYNOPSIS
* _WhatPara( pa_array, pc_string )
*
* DESCRIPTION
* _WhatPara() will copy into an array pa_array the
* character values in the comma delimited string
* pc_string. The array will be created if
* necessary, with as many elements as needed based
* on the comma delimited string. The main intent of
* the _WhatPara() function is as a work-around for
* the seven parameter limit of dBASE IV UDF's.
*
* _WhatPara() will return the number of array
* elements assigned. Note that _WhatPara() will
* overwrite any existing array or variable with the
* same name as pa_array.
*
* There is no explicit limit on the number of data
* elements that the string can contain. (Consult
* the documentation for the maximum length of
* strings in your version of dBASE.)
*
* PARAMETERS
* pa_array = name of array to use or create
* pc_string = comma delimited list of data elements
* to load into the array
* pc_delim = optional delimiter, default is ",". Only the
* first character is used if more than one
* is supplied.
*
* EXAMPLE
*
* ln_howmany = _WhatPara("paralist","1,2,,foo bar,4")
*
* The array: PARALIST[1] = "1"
* PARALIST[2] = "2"
* PARALIST[3] = ""
* PARALIST[4] = "foo bar"
* PARALIST[5] = "4"
*
* ln_howmany = 5
*
* LIMITATIONS
* If the final character of the data string is a
* comma, an error will occur.
*
* VERSION
* dBASE IV 1.1
*
* SEE ALSO:
* COPY TO ARRAY
*
*--------------------------------------------------------------------
PRIVATE lc_args, lc_delimit, lc_lenlook, lc_nxt_tok, lc_posit, ;
lc_str, ln_count
*-- Check for type of look4for string, terminate if not character
IF TYPE("pc_string") <> "C" .OR. TYPE("pa_array") <> "C"
RETURN(.F.)
ENDIF
*-- Check for the existance of the array
IF TYPE("&pa_array[1]") <> "U"
RELEASE &pa_array
ENDIF
*-- Determine number of arguments, and assign it to LC_ARGS
IF TYPE( "PC_DELIM" ) = "C"
lc_delimit = LEFT( pc_delim, 1 )
ELSE
lc_delimit = ","
ENDIF
lc_posit = 1
lc_lenlook = LEN(pc_string)
ln_count = 0
DO WHILE lc_posit < lc_lenlook
IF SUBSTR(pc_string, lc_posit, 1) = lc_delimit
ln_count = ln_count + 1
ENDIF
lc_posit = lc_posit + 1
ENDDO
lc_args = ln_count + 1
*-- Declare the return array pa_array
PUBLIC ARRAY &pa_array[lc_args]
*-- Put the elements in place
lc_posit = 1
lc_str = pc_string
lc_nxt_tok = AT(lc_delimit,lc_str)
DO WHILE lc_nxt_tok > 0
STORE LEFT(lc_str, lc_nxt_tok-1) TO &pa_array[lc_posit]
lc_str = SUBSTR(lc_str, lc_nxt_tok + 1 )
lc_nxt_tok = AT(lc_delimit,lc_str)
lc_posit = lc_posit + 1
ENDDO
STORE LEFT(lc_str, LEN(lc_str)) TO &pa_array[lc_posit]
RETURN (lc_args)
*-- EOF: _WhatPara( pa_array, pc_string )